package com.ymatou.iapi.couponservice.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.couponservice.parameter.GetNeedCancelVirtualCouponBean;
import com.ymatou.iapi.couponservice.service.GetNeedCancelVirtualCouponCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.YmtCouponVirtualRelation;
import com.ymttest.database.sqlwapper.YmtCouponActivityWapper;
import com.ymttest.utils.TestDataManager;

@TestSuite
public class Ts_GetNeedCancelVirtualCoupon {
	private static GetNeedCancelVirtualCouponBean getneedcancelvirtualcouponBean;
	private static GetNeedCancelVirtualCouponCall getneedcancelvirtualcouponCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取需要核销的虚拟券用例");
	}

	@Before
	public void caseUp() {
		getneedcancelvirtualcouponBean=new GetNeedCancelVirtualCouponBean();
		getneedcancelvirtualcouponCall=new GetNeedCancelVirtualCouponCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getneedcancelvirtualcouponCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetNeedCancelVirtualCoupon_001() {
		Logger.start(true,"获取需要核销的虚拟券");
		try {
			
			new YmtCouponActivityWapper().setNeedCancelVirtualCoupon();
			
			getneedcancelvirtualcouponCall.setData(getneedcancelvirtualcouponBean);
			getneedcancelvirtualcouponCall.callService();
			
			Logger.verifyEquals("0", getneedcancelvirtualcouponCall.getStatusCode1(), "验证返回Code");
		    Logger.verifyEquals("操作成功！",
		        		getneedcancelvirtualcouponCall.getMessage(), "验证返回Message");

		    List<String> virtualCouponCodeList = getneedcancelvirtualcouponCall.getVirtualCouponCodeList().getVirtualCouponCodeList();
		    List<YmtCouponVirtualRelation> ralations = new YmtCouponActivityWapper().getNeedCancelVirtualCoupon();
		    
		    List<String> ralationList = new ArrayList<>();
		    
		    int num = ralations.size();
		    for(int i=0;i<num;i++)
		    {
		    	ralationList.add(ralations.get(i).getVirtualCouponCode());
		    }
		    
			Logger.verifyEquals(true,TestDataManager.isListEqual(virtualCouponCodeList, ralationList), "验证返回Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
